package com.m1book.repositories.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import com.m1book.domain.book.Book;
import com.m1book.domain.user.Miser;

@Repository
public class MiserRepositoryImpl implements MiserRepositoryCustom {
	
	@Autowired
	private MongoTemplate mongoTemplate;

	@Override
	public List<Miser> findByAddress(String province, String city) {
		Criteria criteria = Criteria.where("info.province").is(province).and("info.city").is(city);
		Query query = new Query(criteria);
		return mongoTemplate.find(query, Miser.class);
	}

	@Override
	public List<Miser> findBookHolders(Book book, String city, Pageable pageable) {
		Criteria criteria = Criteria.where("info.city").is(city).and("holdBooksId").is(book.getId());
		Query query = new Query(criteria);
		return mongoTemplate.find(query, Miser.class);
	}

	@Override
	public List<Miser> findBookDonaters(Book book, String city, Pageable pageable) {
		Criteria criteria = Criteria.where("info.city").is(city).and("donatBooksId").is(book.getId());
		Query query = new Query(criteria);
		return mongoTemplate.find(query, Miser.class);
	}

}